package com.hdaccp.shuiguoD.controller;

import com.hdaccp.shuiguoD.dao.JinhuoDao;
import com.hdaccp.shuiguoD.entity.Gongying;
import com.hdaccp.shuiguoD.entity.Jinhuo;
import com.hdaccp.shuiguoD.service.JinhuoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jinhuols")
@Scope("prototype")
public class jinhuoController {
    @Autowired
    private JinhuoService jinhuoService;
    @Autowired
    private JinhuoDao jinhuoDao;


    @RequestMapping("/addls")
    @ResponseBody
    public int addls(Jinhuo jinhuols){
        return jinhuoService.addls(jinhuols);
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> querySearch(String huoname,int offset, int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",jinhuoService.findAll(huoname,offset,limit)) ;
        map.put("total",jinhuoService.findTotalCount(huoname)) ;
        return  map ;
    }

    @RequestMapping("/query1")
    @ResponseBody
    public List<Gongying> query1(){
        List<Gongying> list=jinhuoService.query1();
        for (Gongying r:list){
            r.getGname();
        }
        return list;
    }
    @RequestMapping("/scs")
    @ResponseBody
    public int delete(int huoid){
        return jinhuoService.delete(huoid);
    }

    @RequestMapping("/all")
    @ResponseBody
    public boolean all(String huoname, int offset, int limit){
        boolean isok = false;
        if (jinhuoService.findAll(huoname,offset,limit).size() == 0){
            isok = true;
        }

        return  isok ;
    }
}
